package com.xiaoyao.myframeapp.MvpTest.presenter;


import com.xiaoyao.myframeapp.MvpTest.activity.TestActivity;
import com.xiaoyao.myframeapp.MvpTest.bean.Test;
import com.xiaoyao.myframeapp.MvpTest.contract.TestContract;
import com.xiaoyao.myframeapp.MvpTest.model.TestModel;
import com.xiaoyao.myframeapp.mvp.IModel;
import com.xiaoyao.myframeapp.mvp.base.BaseActivity;
import com.xiaoyao.myframeapp.mvp.base.BasePresenter;
import com.xiaoyao.myframeapp.utils.L;

import java.util.HashMap;

/**
 * @author xiaoyao
 * @mail xiao80206040@qq.com
 * @explain
 * @Created by Administrator on 2017/2/27 0027.
 */
public class TestPresenter extends BasePresenter<TestActivity> implements
        TestContract.Presenter {

//    protected static RetrofitService httpService;//json解析

    @Override
    public void login(
            BaseActivity activity,
            String userId,
            String password
    ) {

//        httpService = Http.getRetrofitService();
//
//
//        try {
//            Thread.sleep(3000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//
//        httpService.getVideoUrl(
////                userId,
////                password
//        )
//                .compose(activity.<BaseEntity<Test>>bindUntilEvent(ActivityEvent.DESTROY))//解决
////                .compose(getIView().<BaseEntity<Test>>setThread())//没有进入这里就销毁Activity 空指针
////                .compose(RxScheduler1s.<BaseEntity<Test>>compose())//完成返回Activity 空指针
//                .subscribe(new BaseObserver<Test>(FrameApplication.getmContext()) {
//                               @Override
//                               protected void onHandleSuccess(Test test) {
//                                   L.e("TestPresenter", "onHandleSuccess");
//                                   getIView().Success(test);
//                                   L.e("TestPresenter", "onHandleSuccess");
//                               }
//
//                               @Override
//                               public void onError(Throwable e) {
//                                   super.onError(e);
//                                   L.e("TestPresenter" + "onError");
//                               }
//
//                               @Override
//                               public void onNext(BaseEntity<Test> value) {
//                                   super.onNext(value);
//                                   L.e("TestPresenter" + "onNext");
//                               }
//
//                               @Override
//                               protected void onHandleError(String msg) {
//                                   super.onHandleError(msg);
//                                   L.e("TestPresenter" + "onHandleError");
//                               }
//
//                               @Override
//                               public void onComplete() {
//                                   super.onComplete();
//                                   L.e("TestPresenter" + "onComplete");
//                               }
//
//                               @Override
//                               public void onSubscribe(Disposable d) {
//                                   super.onSubscribe(d);
//                                   L.e("TestPresenter" + "onSubscribe");
//                               }
//
//                           }
//
//                );

//
        ((TestModel) getiModelMap().get("0")).login(
                activity,
                userId,
                password,
                new TestModel
                        .InfoHint() {
                    @Override
                    public void success(Test isData) {
                        if (getIView() == null) {
                            L.e("666666666666666");
                            return;
                        }
                        getIView().Success(isData);  //成功
                    }

                    @Override
                    public void fail(String str) {
                        if (getIView() == null) {
                            L.e("666666666666666");
                            return;
                        }
                        getIView().Fail(str);  //失败
                    }
                });
    }


    @Override
    public HashMap<String, IModel> getiModelMap() {
        return loadModelMap(new TestModel());
    }

    @Override
    public HashMap<String, IModel> loadModelMap(IModel... models) {
        HashMap<String, IModel> map = new HashMap<>();
        for (int i = 0; i < models.length; i++) {
            map.put(i + "", models[i]);
            L.i(getClass(), "i=" + i);
        }
        return map;
    }


}
